﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using WooCoo.Security;

namespace WooCoo.Web.MVC
{
    /// <summary>
    /// 跟MVC用户上下文有关的信息
    /// </summary>
    public class UserContext
    {
        /// <summary>
        /// 用户代码
        /// </summary>
        public static string UserCode { get { return ApplicationContext.User.Identity.Name; } }
        /// <summary>
        /// 用户名称
        /// </summary>
        public static string UserName { get { return FormsAuth.GetLoginer<UserIdentity>().UserName; } }
        /// <summary>
        /// 本地语言
        /// </summary>
        public static string Locale
        {
            get
            {
                return GetUserSetting("locale", "zh_CN");
            }
        }
        /// <summary>
        /// 主题
        /// </summary>
        public static string Theme { get { return GetUserSetting("theme", "default"); } }
        public static string Navigation { get { return GetUserSetting("navigation", "accordion"); } }
        public static string GridRows { get { return GetUserSetting("gridrows", "20"); } }
        public static string HomeTabTitle { get { return GetUserSetting("homeTabTitle", "我的主页"); } }
        public static string HomeTabUrl { get { return GetUserSetting("homeTabUrl", "/home/welcome"); } }
        public static string MaxTabCount { get { return GetUserSetting("maxTabCount", "10"); } }

        public static string GetUserSetting(string settingName, string defaultValue = "")
        {
            if (ApplicationContext.LocalContext.Contains(settingName))
            {
                return ApplicationContext.LocalContext[settingName].ToString();
            }
            return defaultValue;
        }

        public static Dictionary<string, string> GetUserSettings()
        {
            Dictionary<string, string> settings = new Dictionary<string, string>();
            settings["theme"] = Theme;
            settings["navigation"] = Navigation;
            settings["gridrows"] = GridRows;
            settings["homeTabTitle"] = HomeTabTitle;
            settings["homeTabUrl"] = HomeTabUrl;
            settings["maxTabCount"] = MaxTabCount;
            return settings;
        }
    }
}
